package org.baitu.zzim.decoder;

import com.google.protobuf.MessageLite;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
import io.netty.channel.ChannelHandler.Sharable;
import java.util.List;

/**
 * @author zhangkai_a
 * @date 2025/7/3 13:08
 */
@Sharable
public class WebSocketProtobufEncoder extends MessageToMessageEncoder<MessageLite> {
    @Override
    protected void encode(ChannelHandlerContext ctx, MessageLite msg, List<Object> out) {
        byte[] bytes = msg.toByteArray();
        out.add(new BinaryWebSocketFrame(Unpooled.wrappedBuffer(bytes)));
    }
}